﻿#include "thread.h"

HTTP http;

// 实现 WorkThread
WorkThread::WorkThread()
{
    qDebug() <<"WorkThread";
}

// 实现 WorkThread
WorkThread::WorkThread(ThreadPool *parent)
{
    qDebug() <<"WorkThread(ThreadPool *parent)";
    task=new Task();
    m_Pool = parent;
}

WorkThread::~WorkThread()
{
    qDebug() << __FUNCTION__ << m_Handle << "Thread quit: " << isFinished();
    //delete task;
    //delete m_Pool;
    qDebug() <<"~WorkThread";
}


void WorkThread::run()
{
    m_Handle = QThread::currentThreadId();
    while (!m_Pool->m_bStop)
    {
        m_Pool->m_TaskMutex.lock();
        while (m_Pool->M_Tasks.isEmpty()&&m_Pool->DIM_Tasks.isEmpty()&&m_Pool->IM_Tasks.isEmpty()&&m_Pool->LI_Tasks.isEmpty()&&m_Pool->U_Tasks.isEmpty()&&m_Pool->WI_Tasks.isEmpty())//等于空
        {
            qDebug() << QThread::currentThreadId() << "进入等待";
            //阻塞
            m_Pool->m_NotEmpty.wait(&m_Pool->m_TaskMutex);

            qDebug() << QThread::currentThreadId() << "被唤醒";
            // 线程退出条件判断
            if (m_Pool->m_bStop)
            {
                qDebug() << QThread::currentThreadId() << "6";
                m_Pool->m_TaskMutex.unlock();
                return;
            }
        }
        // 取出任务
        if(!m_Pool->M_Tasks.isEmpty())
        {
            task->Indet = m_Pool->M_Tasks.front();
            m_Pool->M_Tasks.pop_front();
        }
        if(!m_Pool->U_Tasks.isEmpty())
        {
            task->Indet = m_Pool->U_Tasks.front().Indet;
            //task->serialport = m_Pool->U_Tasks.front().serialport;
            task->serialportnum = m_Pool->U_Tasks.front().SerialportNum;
            task->UserID= m_Pool->U_Tasks.front().UserID;
            task->Password= m_Pool->U_Tasks.front().Password;
            task->Identnumber= m_Pool->U_Tasks.front().Identnumber;
            task->Device= m_Pool->U_Tasks.front().Device;
            m_Pool->U_Tasks.pop_front();
        }
        if(!m_Pool->DIM_Tasks.isEmpty())
        {
            task->Indet = m_Pool->DIM_Tasks.front().Indet;
            task->serialport=m_Pool->DIM_Tasks.front().serialport;
            task->serialportnum=m_Pool->DIM_Tasks.front().serialportnum;
            task->vid = m_Pool->DIM_Tasks.front().vid;
            task->pid = m_Pool->DIM_Tasks.front().pid;
            task->serialnumber = m_Pool->DIM_Tasks.front().serialnumber;
            task->manufacturer = m_Pool->DIM_Tasks.front().manufacturer;
            task->model = m_Pool->DIM_Tasks.front().model;
            task->route = m_Pool->DIM_Tasks.front().route;
            task->Device = m_Pool->DIM_Tasks.front().Device;
            m_Pool->DIM_Tasks.pop_front();
        }
        if(!m_Pool->IM_Tasks.isEmpty())
        {
            task->Indet = m_Pool->IM_Tasks.front().Indet;
            task->Row = m_Pool->IM_Tasks.front().Row;
            task->Column = m_Pool->IM_Tasks.front().Column;
            task->AppointFirst = m_Pool->IM_Tasks.front().AppointFirst;
            m_Pool->IM_Tasks.pop_front();
        }
        if(!m_Pool->LI_Tasks.isEmpty())
        {
            task->Indet = m_Pool->LI_Tasks.front().Indet;
            task->UserID = m_Pool->LI_Tasks.front().UserID;
            task->Password = m_Pool->LI_Tasks.front().Password;
            task->Identnumber = m_Pool->LI_Tasks.front().Identnumber;
            task->serialportnum = m_Pool->LI_Tasks.front().SerialportNum;
            m_Pool->LI_Tasks.pop_front();
        }
        if(!m_Pool->WI_Tasks.isEmpty())
        {
            task->Indet = m_Pool->WI_Tasks.front().Indet;
            task->StartTime = m_Pool->WI_Tasks.front().StartTime;
            task->EndTime = m_Pool->WI_Tasks.front().EndTime;
            task->ID = m_Pool->WI_Tasks.front().ID;
            task->Name = m_Pool->WI_Tasks.front().Name;
            task->UserID = m_Pool->WI_Tasks.front().UserID;
            m_Pool->WI_Tasks.pop_front();
        }

        //多线程运行
        m_Pool->m_TaskMutex.unlock();
        task->Execute(task->Indet);


    }
}
// 实现 ThreadPool
ThreadPool::ThreadPool()
{
    qDebug() <<"ThreadPool";
}

// 实现 ThreadPool
ThreadPool::ThreadPool(int count, QObject *parent) : QObject(parent), m_bStop(false)
{
    qDebug() <<"ThreadPool(int count, QObject *parent) : QObject(parent), m_bStop(false)";
    for (int i = 0; i < count; i++)
    {
        m_Threads.push_back(QSharedPointer<WorkThread>(new WorkThread(this)));
        qDebug() <<m_Threads.size();
    }
}
void ThreadPool::Threadincrease(int count, QObject *parent)
{
    m_bStop=false;
    qDebug() <<"ThreadPool(int count, QObject *parent) : QObject(parent), m_bStop(false)";
    for (int i = 0; i < count; i++)
    {
        m_Threads.push_back(QSharedPointer<WorkThread>(new WorkThread(this)));
        qDebug() <<m_Threads.size();
    }
}
ThreadPool::~ThreadPool()
{
    qDebug() <<"~ThreadPool()";
    Destroy();
}

//void ThreadPool::PushTask(ThreadInfo threadinfo)
//{
//    //上锁
//    m_TaskMutex.lock();
//    //尾插
//    m_Tasks.push_back(threadinfo);
//    // m_NotEmpty.wakeOne();
//    //解锁
//    m_TaskMutex.unlock();
//}
void ThreadPool::PushTask(UploadInfo threadinfo)
{
    //上锁
    m_TaskMutex.lock();

    //尾插
    U_Tasks.push_back(threadinfo);
    //唤醒
    m_NotEmpty.wakeOne();
    //解锁
    m_TaskMutex.unlock();
}
void ThreadPool::PushTask(int Indet)
{
    //上锁
    m_TaskMutex.lock();

    //尾插
    M_Tasks.push_back(Indet);
    //唤醒
    m_NotEmpty.wakeOne();
    //解锁
    m_TaskMutex.unlock();
}
void ThreadPool::PushTask(DeviceInforMation threadinfo)
{
    //上锁
    m_TaskMutex.lock();
    //尾插
    DIM_Tasks.push_back(threadinfo);
    //唤醒
    m_NotEmpty.wakeOne();
    //解锁
    m_TaskMutex.unlock();
}
void ThreadPool::PushTask(InterfaceMappingInfo threadinfo)
{
    //上锁
    m_TaskMutex.lock();
    //尾插
    IM_Tasks.push_back(threadinfo);
    //唤醒
    m_NotEmpty.wakeOne();
    //解锁
    m_TaskMutex.unlock();
}
void ThreadPool::PushTask(LoginInfo threadinfo)
{
    //上锁
    m_TaskMutex.lock();
    //尾插
    LI_Tasks.push_back(threadinfo);
    //唤醒
    m_NotEmpty.wakeOne();
    //解锁
    m_TaskMutex.unlock();
}
void ThreadPool::PushTask(WarnInstanInfo threadinfo)
{
    //上锁
    m_TaskMutex.lock();
    //尾插
    WI_Tasks.push_back(threadinfo);
    //唤醒
    m_NotEmpty.wakeOne();
    //解锁
    m_TaskMutex.unlock();
}
void ThreadPool::Start(QString threadname)
{
    Name=threadname;

    for (auto thread : m_Threads)
    {
        thread->start();

        // 创建定时器
    }

}

void ThreadPool::Destroy()
{
    qDebug() << "Destroy";
    m_bStop = true;
    m_NotEmpty.wakeAll();

    // 等待线程退出
    for (auto thread : m_Threads)
    {
        if (!thread->isFinished())
        {
            thread->quit();
            //thread->terminate();//强制结束
            thread->wait();
        }
    }

    // 清空智能指针自动释放
    m_Threads.clear();
}
void ThreadPool::a()
{
    m_NotEmpty.wakeAll();
    //m_bStop = true;
    // 等待线程退出
    for (auto thread : m_Threads)
    {
        qDebug() << "超时解析"<< thread->currentThreadId();
        thread->terminate();
        thread->wait();// 等待回收资源
    }
    // 清空智能指针自动释放
    //m_Threads.clear();
    //m_Threads.pop_front();
    IsC7=true;
    return;

}

// 实现 ThreadPool
Task::Task()
{
    qDebug()<<"task默认构造";
}

Task::~Task()
{
    qDebug()<<"task析构";
}


void Task::Execute(int index)
{
    switch (index) {

    case TNOTICE://获取公告
    {
        qint64 timestamp1 = QDateTime::currentMSecsSinceEpoch();
        if(timestamp1-Noticetimes>=60000)//60s
        {
            Noticetimes=timestamp1;
            if(http.GetNotice())
            {
                emit GlobalSignals::instance().SendUiMessageNotifica(ACQUISITION_STATION,UPDATE_CONTROL_S,BACKCONNECTION,"","",SUCCESS,-1);
                NoticeFailNum=0;
                for(int i=0;i<Notice.size();i++)
                {
                    QThread::msleep(2000);
                    if(i==0)
                    {
                        config.WriteInfo(QString("Notice[i].AnnouncementTitle=%1,timestamp=%2,Lasttimes=%3").arg(Notice[i].AnnouncementTitle).arg(Notice[i].AnnouncementContent).arg(Notice[i].AnnouncementTime));
                        emit GlobalSignals::instance().SendUiMessageNotifica(ACQUISITION_STATION,UPDATE_CONTROL_S,NOTICE_UI,QString("%1*/%2*/%3*/%4").arg(Notice[i].AnnouncementTitle).arg(Notice[i].AnnouncementContent).arg(Notice[i].AnnouncementTime).arg(Notice[i].AnnouncementCc),"",0,-1);
                    }
                    else
                    {

                        config.WriteInfo(QString("Notice[1].AnnouncementTitle=%1,timestamp=%2,Lasttimes=%3").arg(Notice[i].AnnouncementTitle).arg(Notice[i].AnnouncementContent).arg(Notice[i].AnnouncementTime));
                        emit GlobalSignals::instance().SendUiMessageNotifica(ACQUISITION_STATION,UPDATE_CONTROL_S,NOTICE_UI,QString("%1*/%2*/%3*/%4").arg(Notice[i].AnnouncementTitle).arg(Notice[i].AnnouncementContent).arg(Notice[i].AnnouncementTime).arg(Notice[i].AnnouncementCc),"",1,-1);
                    }
                }
            }
            else
            {
                NoticeFailNum++;
                if(NoticeFailNum>=5)
                {
                    emit GlobalSignals::instance().SendUiMessageNotifica(ACQUISITION_STATION,UPDATE_CONTROL_S,BACKCONNECTION,"","",FAIL,-1);
                }
            }
        }
        //如果索引文件过多，一直掉接口CPU会跑满
        if(timestamp1-Lasttimes>=3600000)//3600s
        {

            Lasttimes=timestamp1;
            //            QJsonArray dataArray;
            //            config.WriteInfo(BVersion);
            //            if(BVersion=="V5"||BVersion=="Python")
            //            {
            //                for(auto it=ARQList.begin();it!=ARQList.end();){
            //                    RetranSmission arg;
            //                    arg.fileName=it->fileName;
            //                    arg.Identnumber=it->Identnumber;
            //                    arg.UserID=it->UserID;
            //                    QJsonObject jsonObject;
            //                    jsonObject["police_num"] =  arg.UserID;
            //                    jsonObject["dev_id"] = arg.Identnumber;
            //                    jsonObject["file_name"] = arg.fileName;
            //                    jsonObject["data_path"] = "";
            //                    it++;
            //                    dataArray.append(jsonObject);

            //                }

            //            }
            //            else
            //            {
            //                for(auto it=ARQList.begin();it!=ARQList.end();){
            //                    RetranSmission arg;
            //                    arg.fileName=it->fileName;
            //                    arg.Identnumber=it->Identnumber;
            //                    arg.UserID=it->UserID;
            //                    QJsonObject jsonObject;
            //                    jsonObject["police_num"] =  arg.UserID;
            //                    jsonObject["dev_id"] = arg.Identnumber;
            //                    jsonObject["file_name"] = arg.fileName;
            //                    jsonObject["data_path"] = "";
            //                    it++;
            //                    dataArray.append(jsonObject);

            //                }
            //            }
            //            if(http.V6uploadLogCustom(dataArray)==1)
            //            {
            //                config.WriteInfo(QString("重传成功"));
            //                ARQList.clear();
            //            }
        }
       NetwordName=config.NetwordName;
       qDebug() << "NetwordName="<<NetwordName;

        sys.updateSpeed();
        sys.getMemUsage();
        sys.getDiskSpeed();
        sys.getNetUsage();
        sys.getCpuInfo();
        sys.getPathSpace(config.MountUrl);


        emit GlobalSignals::instance().SendUiMessageNotifica(ACQUISITION_STATION,UPDATE_CONTROL_S,CPU_UI,QString("%1;%2;%3; 下载:%4  上传:%5").arg(CPU).arg(Memory).arg(Disk).arg(DoNetword).arg(UpNetword),"",STATELESS,-1);
        //BackError=0;
        //emit GlobalSignals::instance().Print("");
        //        emit GlobalSignals::instance().SendUiMessageNotifica(ACQUISITION_STATION,UPDATE_CONTROL_S,NOTICE_UI,Notice,"",STATELESS,-1);
        //        emit GlobalSignals::instance().SendUiMessageNotifica(ACQUISITION_STATION,UPDATE_CONTROL_S,CPU_UI,QString("%1%").arg(CPU),"",STATELESS,-1);
        //        emit GlobalSignals::instance().SendUiMessageNotifica(ACQUISITION_STATION,UPDATE_CONTROL_S,MEMORY_UI,QString("%1").arg(Memory),"",STATELESS,-1);
        //        emit GlobalSignals::instance().SendUiMessageNotifica(ACQUISITION_STATION,UPDATE_CONTROL_S,DISK_UI,QString("%1 G").arg(Disk),"",STATELESS,-1);
        //        emit GlobalSignals::instance().SendUiMessageNotifica(ACQUISITION_STATION,UPDATE_CONTROL_S,NETWORK_UI,QString("上传:%1/下载:%2").arg(UpNetword).arg(DoNetword),"",STATELESS,-1);
        qDebug() << "获取公告";

        //  config.WriteInfo(QString("获取公告%1").arg(Notice));
        break;
    }
    case LOCKLABEL://锁定图标
    {
        //        QString username="";
        //        QString password="";
        //        config.ReadInfo("config.ini","TheLocalKey",username);
        //        config.ReadInfo("config.ini","TheLocalKeyPDW",password);
        config.WriteInfo(QString("password%1").arg(config.TheLocalKey));
        config.WriteInfo(QString("password%1").arg(config.TheLocalKeyPDW));
        if(Password==config.TheLocalKeyPDW&&UserID==config.TheLocalKey)
        {
            config.WriteInfo(QString("登录成功!"));
            emit GlobalSignals::instance().SendMessageNotifica(ACQUISITION_STATION,LOCK_LABEL_S,SUCCESS);

        }
        else
        {
            int price=http.V6getCheckUser(UserID, Password, 0);
            if(price==1||price==2)
            {
                config.WriteInfo(QString("登录成功!"));
                emit GlobalSignals::instance().SendMessageNotifica(ACQUISITION_STATION,LOCK_LABEL_S,SUCCESS);

            }
            else
            {

                config.WriteInfo(QString("登录失败!"));
                emit GlobalSignals::instance().SendMessageNotifica(ACQUISITION_STATION,LOCK_LABEL_S,FAIL);

            }
        }

        break;
    }
    case INTERFACEMAPPING://接口映射
    {
        QString username="";
        QString password="";
        //        config.ReadInfo("config.ini","TheLocalKey",username);
        //        config.ReadInfo("config.ini","TheLocalKeyPDW",password);
        //        config.WriteInfo(QString("password%1").arg(username));
        //        config.WriteInfo(QString("password%1").arg(password));
        if(Password==config.TheLocalKeyPDW&&UserID==config.TheLocalKey)
        {
            config.WriteInfo(QString("登录成功!"));
            emit GlobalSignals::instance().SendMessageNotifica(ACQUISITION_STATION,INTERFACE_MAPPING_S,SUCCESS);
            InterfaceMappingInfo Info;
            Info.Indet=0;
            Info.Row=row;
            Info.Column=column;
            Info.AppointFirst=AppointFirstNum;
            QThread::msleep(500);
            emit GlobalSignals::instance().SendIMMessageNotifica(ACQUISITION_STATION,INTERFACE_MAPPING_INFO_S,Info);
            IsTerface=true;
        }
        else
        {
            QString ResultMess = "";
            int UserPrevilege = 0;
            if(http.V6getCheckUser(UserID, Password, 0))
            {
                config.WriteInfo(QString("登录成功!"));
                emit GlobalSignals::instance().SendMessageNotifica(ACQUISITION_STATION,INTERFACE_MAPPING_S,SUCCESS);
                InterfaceMappingInfo Info;
                Info.Indet=0;
                Info.Row=row;
                Info.Column=column;
                Info.AppointFirst=AppointFirstNum;
                QThread::msleep(500);
                emit GlobalSignals::instance().SendIMMessageNotifica(ACQUISITION_STATION,INTERFACE_MAPPING_INFO_S,Info);
                IsTerface=true;
            }
            else
            {
                IsTerface=false;
                config.WriteInfo(QString("登录失败!"));
                emit GlobalSignals::instance().SendMessageNotifica(ACQUISITION_STATION,INTERFACE_MAPPING_S,FAIL);

            }
        }

        break;
    }
    case INTERFACEMAPPING_SAVE://接口映射保存
    {
        IsTerface=false;
        row=Row;
        column=Column;
        AppointFirstNum=AppointFirst;
        //config.WriteInfo(QString("%1").arg(AppointFirst));
        //config.WriteInfo(AppointFirst);
        config.WriteInfo(QString("INTERFACEMAPPING_SAVE=.%1!").arg(AppointFirst));
        if(config.UpdateXmlKeyValue("config.ini","List",QString("%1").arg(Column))&&
                config.UpdateXmlKeyValue("config.ini","Row",QString("%1").arg(Row))&&
                config.UpdateXmlKeyValue("config.ini","Prior",QString("%1").arg(AppointFirst)))
        {
            AnalysisPath.clear();
            AnalysisPath=TemporaryPath;

            //int a=0;
            QString p[26];
            myVec.clear();
            std::multimap<int, QString>::iterator it = TemporaryPath.begin();
            for(int i=1;i<=SYSTEMROW*SYSTEMLIST;i++)
            {
                DeviceInforMation deviceinfo;
                deviceinfo.Indet=-1;
                deviceinfo.serialportnum=i;

                deviceinfo.serialport="";
                deviceinfo.vid= "";//vid
                deviceinfo.pid= "";//pid
                deviceinfo.serialnumber= "";//设备序列号
                deviceinfo.manufacturer= "";//设备制造商 3
                deviceinfo.model= "";//设备型号 4
                deviceinfo.route= "";//位置路径
                deviceinfo.Device= "";// 是否为优先
                deviceinfo.Identnumber= "";// 是否为优先
                index=i;
                while (it != TemporaryPath.end())
                {

                    if(index==(*it).first)//等于上一个
                    {

                        deviceinfo.serialport+=(*it).second;
                        deviceinfo.serialport+=";";
                    }

                    if((*it).first>index)
                        break;
                    ++it;
                }
                p[index]= deviceinfo.serialport;
                if(config.UpdateRouteValueInfo("config_route.ini",QString("Initalize_%1").arg(i),p[i]))//将串口写入
                {
                    config.WriteInfo(QString("接口映射保存%1=%2!").arg(i).arg(p[i]));
                }
                myVec.push_back(deviceinfo);
            }
            InterfaceMappingInfo Info;
            Info.Indet=0;
            Info.Row=row;
            Info.Column=column;
            Info.AppointFirst=AppointFirstNum;


            emit GlobalSignals::instance().SendMessageNotifica(ACQUISITION_STATION,INTERFACE_MAPPING_SAVE_S,SUCCESS);
            QThread::msleep(500);
            emit GlobalSignals::instance().SendIMMessageNotifica(ACQUISITION_STATION,INTERFACE_MAPPING_INFO_S,Info);
        }
        else {
            emit GlobalSignals::instance().SendMessageNotifica(ACQUISITION_STATION,INTERFACE_MAPPING_SAVE_S,FAIL);
        }

        break;
    }

    case INTERFACEMAPPING_EXIT:
    {
        IsTerface=false;
        TemporaryPath.clear();
        emit GlobalSignals::instance().SendMessageNotifica(ACQUISITION_STATION,INTERFACE_MAPPING_EXIT_S,SUCCESS);
        break;
    }
    case BACKGROUNDLOGIN:
    {
        if(http.V6GetUserByPoliceNum(0,UserID, Password))
        {
            config.WriteInfo(QString("登录成功!"));
            emit GlobalSignals::instance().SendMessageNotifica(ACQUISITION_STATION,INTERFACE_BACKGROUND_LOGIN_S,SUCCESS);
        }
        else
        {
            config.WriteInfo(QString("登录失败!"));
            emit GlobalSignals::instance().SendMessageNotifica(ACQUISITION_STATION,INTERFACE_BACKGROUND_LOGIN_S,FAIL);

        }

        break;
    }
    case QUERY:
    {
        int price=http.V6getCheckUser(UserID, Password, 0);
        if(price==1)
        {
       config.WriteInfo(QString("登录成功!%1").arg(UserID));
        emit GlobalSignals::instance().SendMessageNotifica(ACQUISITION_STATION,INTERFACE_QUERY_S,SUCCESS);
        }
        else if(price==2)
        {
       config.WriteInfo(QString("登录成功!%1").arg(UserID));
        emit GlobalSignals::instance().SendMessageNotifica(ACQUISITION_STATION,INTERFACE_QUERY_S,SUCCESS_ADMIN);
        }
        else
        {
       config.WriteInfo(QString("登录失败!"));
        emit GlobalSignals::instance().SendMessageNotifica(ACQUISITION_STATION,INTERFACE_QUERY_S,FAIL);

        }


//        if(http.V6GetUserByPoliceNum(0,UserID, Password))
//        {
//            config.WriteInfo(QString("登录成功!"));
//            emit GlobalSignals::instance().SendMessageNotifica(ACQUISITION_STATION,INTERFACE_QUERY_S,SUCCESS);
//        }
//        else
//        {
//            config.WriteInfo(QString("登录失败!"));
//            emit GlobalSignals::instance().SendMessageNotifica(ACQUISITION_STATION,INTERFACE_QUERY_S,FAIL);

//        }
        break;
    }
    case TUPLOAD_LOGIN:
    {
        if(http.V6GetUserByPoliceNum(serialportnum-100,UserID, Password))
        {
            if(IsWarnInstance)//警情模式
            {
                http.GetClassifcationType();
                emit GlobalSignals::instance().SendPoliceMode(ACQUISITION_STATION,DEPARTMENT_FILE_QUERY_S);
            }
            else
            {
                config.WriteInfo(QString("登录成功!AppointFirstNum=%1").arg(AppointFirstNum));
                if(AppointFirstNum==serialportnum-100)
                {
                    config.WriteInfo(QString("进来了？=%1").arg(serialportnum));
                    emit GlobalSignals::instance().ThreadPriorUpload(serialportnum,UserID,Password);
                }
                else
                {
                    config.WriteInfo(QString("进来了？1=%1").arg(serialportnum));
                    config.WriteInfo(QString("进来了？1=%1").arg(UserID));
                    emit GlobalSignals::instance().ThreadUpload(serialportnum,UserID,Password);
                }
                // emit GlobalSignals::instance().SendUiMessageNotifica(ACQUISITION_STATION,UPDATE_CONTROL_S,serialportnum,"",QString("%1;%2;%3;%4").arg(UserID).arg(userName[serialportnum-100]).arg(Identnumber).arg(unitName[serialportnum-100]),UPLOADING,-1);
            }

        }
        else
        {
            emit GlobalSignals::instance().SendMessageNotifica(ACQUISITION_STATION,UPLOAD_S,FAIL);
        }
        break;
    }
        //    case THREAD3A://s3,c8,c9,c6,s1
        //    {
        //        Is3A=false;

        //        if(TCLT6RotaryTable(serialnumber,Identnumber,"888888"))
        //        {
        //            config.WriteInfo(QString("之前Identnumber%1").arg(Identnumber));
        //            Identnumber = Identnumber.mid(0, 7); // 从索引10开始截取长度为8的子串
        //            config.WriteInfo(QString("之后Identnumber%1").arg(Identnumber));
        //            qInfo()<<"Identnumber"<<Identnumber;
        //            IsBackdll[serialport]=1;//磁盘模式

        //            if(IsUdisk[serialport]!="")
        //            {
        //                IsBackdll[serialportnum]=2;//磁盘模式
        //                qDebug() << "handleThreadResultb";
        //                config.WriteInfo(QString("IsUdisk[Indet]!=%1").arg(IsUdisk[serialportnum]));
        //                config.WriteInfo(QString("TCLT6,serialnumber%1").arg(serialportnum));
        //                emit GlobalSignals::instance().SendUiMessageNotifica(ACQUISITION_STATION,UPDATE_CONTROL_S,serialportnum+100,"",QString("%1;%2").arg(IsUdisk[serialportnum]).arg(IdentNumber[serialportnum]),DISKMODE,-1);
        //                //emit GlobalSignals::instance().SetLabel(Indet+100,"",QString("盘符路径:%1\n序列号:%2").arg(IsUdisk[SerialportNum]).arg(IdentNumber[SerialportNum]),"磁盘模式",-1);
        //            }
        //            else
        //            {
        //                qDebug() << "handleThreadResultc";

        //                IdentNumber[serialportnum]=Identnumber;
        //                qDebug() << "handleThreadResultc"<<IdentNumber[serialportnum]<<"Indet"<<Indet;
        //                IsBackdll[serialportnum]=1;
        //                //根据对应串口位置修改内存中设备信息3
        //                config.WriteInfo(QString("IsUdisk[Indet]==%1").arg(IsUdisk[serialportnum]));
        //                config.WriteInfo(QString("TCLT6,serialnumber%1").arg(serialportnum));
        //                emit GlobalSignals::instance().SendUiMessageNotifica(ACQUISITION_STATION,UPDATE_CONTROL_S,serialportnum+100,"","",TURNTABLESUCCESSFUL,-1);
        //                // emit GlobalSignals::instance().SetLabel(SerialportNum+100,"","","转盘成功",-1);//主进程进行这个

        //                qDebug() << "handleThreadResultd";
        //            }
        //            Is3A=true;
        //            break;
        //        }
        //        else if(TCLT6RotaryTable(serialnumber,Identnumber,"000000"))
        //        {
        //            config.WriteInfo(QString("之前Identnumber%1").arg(Identnumber));
        //            Identnumber = Identnumber.mid(0, 7); // 从索引10开始截取长度为8的子串
        //            config.WriteInfo(QString("之后Identnumber%1").arg(Identnumber));
        //            IsBackdll[serialportnum]=1;//磁盘模式

        //            if(IsUdisk[serialportnum]!="")
        //            {
        //                IsBackdll[serialportnum]=2;//磁盘模式
        //                qDebug() << "handleThreadResultb";
        //                config.WriteInfo(QString("IsUdisk[Indet]!=%1").arg(IsUdisk[serialportnum]));
        //                config.WriteInfo(QString("TCLT6,serialnumber%1").arg(serialportnum));
        //                emit GlobalSignals::instance().SendUiMessageNotifica(ACQUISITION_STATION,UPDATE_CONTROL_S,serialportnum+100,"",QString("%1;%2").arg(IsUdisk[serialportnum]).arg(IdentNumber[serialportnum]),DISKMODE,-1);
        //                //emit GlobalSignals::instance().SetLabel(Indet+100,"",QString("盘符路径:%1\n序列号:%2").arg(IsUdisk[SerialportNum]).arg(IdentNumber[SerialportNum]),"磁盘模式",-1);
        //            }
        //            else
        //            {
        //                qDebug() << "handleThreadResultc";

        //                IdentNumber[serialportnum]=Identnumber;
        //                qDebug() << "handleThreadResultc"<<IdentNumber[serialportnum]<<"Indet"<<serialportnum;
        //                IsBackdll[serialportnum]=1;
        //                //根据对应串口位置修改内存中设备信息3
        //                config.WriteInfo(QString("IsUdisk[Indet]==%1").arg(IsUdisk[serialportnum]));
        //                config.WriteInfo(QString("TCLT6,serialnumber%1").arg(serialportnum));
        //                emit GlobalSignals::instance().SendUiMessageNotifica(ACQUISITION_STATION,UPDATE_CONTROL_S,serialportnum+100,"","",TURNTABLESUCCESSFUL,-1);
        //                // emit GlobalSignals::instance().SetLabel(SerialportNum+100,"","","转盘成功",-1);//主进程进行这个

        //                qDebug() << "handleThreadResultd";
        //            }
        //            Is3A=true;
        //            break;
        //        }
        //        else if(TCL3ARotaryTable(serialnumber,Identnumber,"123456"))
        //        {
        //            config.WriteInfo(QString("之前Identnumber%1").arg(Identnumber));
        //            Identnumber = Identnumber.mid(0, 7); // 从索引10开始截取长度为8的子串
        //            config.WriteInfo(QString("之后Identnumber%1").arg(Identnumber));
        //            IsBackdll[serialportnum]=1;//磁盘模式

        //            if(IsUdisk[serialportnum]!="")
        //            {
        //                IsBackdll[serialportnum]=2;//磁盘模式
        //                qDebug() << "handleThreadResultb";
        //                config.WriteInfo(QString("IsUdisk[Indet]!=%1").arg(IsUdisk[serialportnum]));
        //                config.WriteInfo(QString("THREAD3A,serialnumber%1").arg(serialportnum));
        //                emit GlobalSignals::instance().SendUiMessageNotifica(ACQUISITION_STATION,UPDATE_CONTROL_S,serialportnum+100,"",QString("%1;%2").arg(IsUdisk[serialportnum]).arg(IdentNumber[serialportnum]),DISKMODE,-1);
        //                //emit GlobalSignals::instance().SetLabel(Indet+100,"",QString("盘符路径:%1\n序列号:%2").arg(IsUdisk[SerialportNum]).arg(IdentNumber[SerialportNum]),"磁盘模式",-1);
        //            }
        //            else
        //            {
        //                qDebug() << "handleThreadResultc";

        //                IdentNumber[serialportnum]=Identnumber;
        //                qDebug() << "handleThreadResultc"<<IdentNumber[serialportnum]<<"Indet"<<serialportnum;
        //                IsBackdll[serialportnum]=1;
        //                //根据对应串口位置修改内存中设备信息3
        //                config.WriteInfo(QString("IsUdisk[Indet]==%1").arg(IsUdisk[Indet]));
        //                config.WriteInfo(QString("THREAD3A,serialnumber%1").arg(serialportnum));
        //                emit GlobalSignals::instance().SendUiMessageNotifica(ACQUISITION_STATION,UPDATE_CONTROL_S,serialportnum+100,"","",TURNTABLESUCCESSFUL,-1);
        //                // emit GlobalSignals::instance().SetLabel(SerialportNum+100,"","","转盘成功",-1);//主进程进行这个

        //                qDebug() << "handleThreadResultd";
        //            }
        //            Is3A=true;
        //            break;
        //        }
        //        else  if(TCLR1RotaryTable(serialnumber,Identnumber,"888888"))
        //        {
        //            config.WriteInfo(QString("之前Identnumber%1").arg(Identnumber));
        //            Identnumber = Identnumber.mid(0, 7); // 从索引10开始截取长度为8的子串
        //            config.WriteInfo(QString("之后Identnumber%1").arg(Identnumber));
        //            IsBackdll[serialportnum]=1;//磁盘模式

        //            if(IsUdisk[serialportnum]!="")
        //            {
        //                IsBackdll[serialportnum]=2;//磁盘模式
        //                qDebug() << "handleThreadResultb";
        //                config.WriteInfo(QString("IsUdisk[Indet]!=%1").arg(IsUdisk[serialportnum]));
        //                config.WriteInfo(QString("THREADR1,serialnumber%1").arg(serialportnum));
        //                emit GlobalSignals::instance().SendUiMessageNotifica(ACQUISITION_STATION,UPDATE_CONTROL_S,serialportnum+100,"",QString("%1;%2").arg(IsUdisk[serialportnum]).arg(IdentNumber[serialportnum]),DISKMODE,-1);
        //                //emit GlobalSignals::instance().SetLabel(Indet+100,"",QString("盘符路径:%1\n序列号:%2").arg(IsUdisk[SerialportNum]).arg(IdentNumber[SerialportNum]),"磁盘模式",-1);
        //            }
        //            else
        //            {
        //                qDebug() << "handleThreadResultc";

        //                IdentNumber[serialportnum]=Identnumber;
        //                qDebug() << "handleThreadResultc"<<IdentNumber[serialportnum]<<"Indet"<<serialportnum;
        //                IsBackdll[serialportnum]=1;
        //                //根据对应串口位置修改内存中设备信息3
        //                config.WriteInfo(QString("IsUdisk[Indet]==%1").arg(IsUdisk[serialportnum]));
        //                config.WriteInfo(QString("THREADR1,serialnumber%1").arg(serialportnum));
        //                emit GlobalSignals::instance().SendUiMessageNotifica(ACQUISITION_STATION,UPDATE_CONTROL_S,serialportnum+100,"","",TURNTABLESUCCESSFUL,-1);
        //                // emit GlobalSignals::instance().SetLabel(SerialportNum+100,"","","转盘成功",-1);//主进程进行这个

        //                qDebug() << "handleThreadResultd";
        //            }
        //            Is3A=true;
        //            break;
        //        }
        //        else
        //        {
        //            qInfo()<<"operator0";
        //            //IsBackdll[SerialportNum]=-1;//磁盘模式
        //            //根据对应串口位置修改内存中设备信息
        //            emit GlobalSignals::instance().SendUiMessageNotifica(ACQUISITION_STATION,UPDATE_CONTROL_S,serialportnum+100,"","",TURNTABLEFAILED,-1);
        //            //emit GlobalSignals::instance().SetLabel(SerialportNum+100,"","","转盘失败",-1);
        //            qDebug() << "handleThreadResult0"<<serialnumber;
        //            Is3A=true;
        //            break;
        //        }


        //    }


    case THREADC6://s3,c8,c9,c6,s1,s2
    {
        qInfo()<<"THREADC6";
        IsC6=false;
        int electricity=0;
        //        qInfo()<<"operator";
        //        QString processName = QString("adb -s %1 shell am broadcast -a \"tcl-mass-storage\"").arg(serialnumber);
        QProcess process;
        //        process.start(processName);
        //        process.waitForFinished(-1); // 等待进程完成
        //        if (process.exitCode() == 0) {
        //            QString output = process.readAllStandardOutput();
        //            qDebug() << "命令输出： " << output;
        //            qDebug() <<QString("ADB命令发送成功：%1").arg(output);
        //            Identnumber=serialnumber;
        //        }
        //processName = QString("adb -s %1 shell am broadcast -a \"tcl-mass-storage\"").arg(serialnumber);

        process.start("pkill adb");
        process.waitForFinished(-1); // 等待进程完成

        process.start("pkill mcs8adb");
        process.waitForFinished(-1); // 等待进程完成
        QThread::msleep(3000);
 if(TCLC6RotaryTable(serialnumber,Identnumber))
      //  if(ZJXS2RotaryTable(serialnumber,Identnumber,&electricity))
        {
            qInfo()<<"Identnumber"<<Identnumber;
            Identnumber = Identnumber.mid(Identnumber.length()-7, 7); // 从索引10开始截取长度为7的子串
            qInfo()<<"Identnumber"<<Identnumber;
            qInfo()<<"electricity"<<electricity;
            qInfo()<<"serialportnum"<<serialportnum;
            IsBackdll[serialportnum]=1;//磁盘模式
            IdentElectricity[serialportnum]=electricity;
             qInfo()<<"IdentElectricity[serialportnum]"<<IdentElectricity[serialportnum];
            if(IsUdisk[serialportnum]!="")
            {
                IsBackdll[serialportnum]=2;//磁盘模式
         qInfo()<<"IdentElectricity[serialportnum]"<<IdentElectricity[serialportnum];
                config.WriteInfo(QString("IsUdisk[Indet]!=%1").arg(IsUdisk[serialportnum]));
                config.WriteInfo(QString("THREADC6,serialnumber%1").arg(serialportnum));
                emit GlobalSignals::instance().SendUiMessageNotifica(ACQUISITION_STATION,UPDATE_CONTROL_S,serialportnum+100,"",QString("%1;%2;%3").arg(IsUdisk[serialportnum]).arg(IdentNumber[serialportnum]).arg(IdentElectricity[serialportnum]),DISKMODE,-1);
                //emit GlobalSignals::instance().SetLabel(Indet+100,"",QString("盘符路径:%1\n序列号:%2").arg(IsUdisk[SerialportNum]).arg(IdentNumber[SerialportNum]),"磁盘模式",-1);
            }
            else
            {
                qDebug() << "handleThreadResultc";
                //int index=GetMyVec("", Indet);
                if (index != 0) {

                    IdentNumber[serialportnum]=Identnumber;
                }
                IsBackdll[serialportnum]=1;
                //根据对应串口位置修改内存中设备信息3
                config.WriteInfo(QString("IsUdisk[serialportnum]==%1").arg(IsUdisk[serialportnum]));
                config.WriteInfo(QString("THREADC6,serialnumber%1").arg(serialportnum));
                emit GlobalSignals::instance().SendUiMessageNotifica(ACQUISITION_STATION,UPDATE_CONTROL_S,serialportnum+100,"","",TURNTABLESUCCESSFUL,-1);
                // emit GlobalSignals::instance().SetLabel(SerialportNum+100,"","","转盘成功",-1);//主进程进行这个

                qDebug() << "handleThreadResultd";
            }

        }
        else
        {
            qInfo()<<"operator0";
            //IsBackdll[SerialportNum]=-1;//磁盘模式
            //根据对应串口位置修改内存中设备信息
            emit GlobalSignals::instance().SendUiMessageNotifica(ACQUISITION_STATION,UPDATE_CONTROL_S,serialportnum+100,"","",TURNTABLEFAILED,-1);
            //emit GlobalSignals::instance().SetLabel(SerialportNum+100,"","","转盘失败",-1);
            qDebug() << "handleThreadResult0"<<serialnumber;
        }
        //        // 获取当前目录路径
        //        QString currentPath = QDir::currentPath();

        //        // 检查当前目录是否存在
        //        QString aDllPath = currentPath + "/TMUsb.exe";
        //        QFile aDllFile(aDllPath);

        //        if (!aDllFile.exists()) {
        //            // 如果不存在a.dll，拷贝D文件夹下的b.dll到当前目录
        //            QString dFolderPath = currentPath + "/C6";
        //            QString bDllPath = dFolderPath + "/TMUsb.exe";

        //            QFile bDllFile(bDllPath);

        //            if (bDllFile.exists()) {
        //                // 如果D文件夹下的b.dll存在，拷贝到当前目录
        //                bDllFile.copy(aDllPath);
        //                config.WriteInfo("拷贝TMUsb.exe");
        //            } else {
        //                config.WriteInfo("C6/TMUsb.exe不存在");
        //            }
        //        }


        //        if(TCLC6RotaryTable(serialnumber,Identnumber))
        //        {
        //            qInfo()<<"Identnumber"<<Identnumber;
        //            Identnumber = Identnumber.mid(Identnumber.length()-7, 7); // 从索引10开始截取长度为7的子串
        //            qInfo()<<"Identnumber"<<Identnumber;
        //            IsBackdll[serialportnum]=1;//磁盘模式

        //            if(IsUdisk[serialportnum]!="")
        //            {
        //                IsBackdll[serialportnum]=2;//磁盘模式
        //                qDebug() << "handleThreadResultb";
        //                config.WriteInfo(QString("IsUdisk[Indet]!=%1").arg(IsUdisk[serialportnum]));
        //                config.WriteInfo(QString("THREADC6,serialnumber%1").arg(serialportnum));
        //                emit GlobalSignals::instance().SendUiMessageNotifica(ACQUISITION_STATION,UPDATE_CONTROL_S,serialportnum+100,"",QString("%1;%2").arg(IsUdisk[serialportnum]).arg(IdentNumber[serialportnum]),DISKMODE,-1);
        //                //emit GlobalSignals::instance().SetLabel(Indet+100,"",QString("盘符路径:%1\n序列号:%2").arg(IsUdisk[SerialportNum]).arg(IdentNumber[SerialportNum]),"磁盘模式",-1);
        //            }
        //            else
        //            {
        //                qDebug() << "handleThreadResultc";
        //                //int index=GetMyVec("", Indet);
        //                if (index != 0) {

        //                    IdentNumber[serialportnum]=Identnumber;
        //                }
        //                IsBackdll[serialportnum]=1;
        //                //根据对应串口位置修改内存中设备信息3
        //                config.WriteInfo(QString("IsUdisk[serialportnum]==%1").arg(IsUdisk[serialportnum]));
        //                config.WriteInfo(QString("THREADC6,serialnumber%1").arg(serialportnum));
        //                emit GlobalSignals::instance().SendUiMessageNotifica(ACQUISITION_STATION,UPDATE_CONTROL_S,serialportnum+100,"","",TURNTABLESUCCESSFUL,-1);
        //                // emit GlobalSignals::instance().SetLabel(SerialportNum+100,"","","转盘成功",-1);//主进程进行这个

        //                qDebug() << "handleThreadResultd";
        //            }

        //        }
        //        else
        //        {
        //            qInfo()<<"operator0";
        //            //IsBackdll[SerialportNum]=-1;//磁盘模式
        //            //根据对应串口位置修改内存中设备信息
        //            emit GlobalSignals::instance().SendUiMessageNotifica(ACQUISITION_STATION,UPDATE_CONTROL_S,serialportnum+100,"","",TURNTABLEFAILED,-1);
        //            //emit GlobalSignals::instance().SetLabel(SerialportNum+100,"","","转盘失败",-1);
        //            qDebug() << "handleThreadResult0"<<serialnumber;
        //        }
        IsC6=true;
        break;
    }
    case THREADC7: //c7
    {
        IsC7=false;
        // QString text;
        // 获取当前目录路径
        QString processName = "TMUsb.exe";
        QProcess process;
        process.start("taskkill", QStringList() << "/F" << "/IM" << processName);
        process.waitForFinished(-1); // 等待进程完成
        processName = "adb.exe";
        process.start("taskkill", QStringList() << "/F" << "/IM" << processName);
        process.waitForFinished(-1); // 等待进程完成
        //    QString targetProcessPath = "./TCL_C6/TMUsb.exe";
        //       terminateProcessByPath(targetProcessPath);
        QThread::msleep(1000);

        QString currentPath = QDir::currentPath();

        // 检查当前目录是否存在
        QString aDllPath = currentPath + "/TMUsb.exe";
        QFile aDllFile(aDllPath);

        if (aDllFile.exists()) {
            aDllFile.remove();
            config.WriteInfo("删除的TMUsb.exe");
        }
        if(TMC7RotaryTable(serialnumber,Identnumber))
        {
            qInfo()<<"Identnumber"<<Identnumber;
            Identnumber = Identnumber.mid(Identnumber.length()-7, 7); // 从索引10开始截取长度为8的子串
            qInfo()<<"Identnumber"<<Identnumber;
            IsBackdll[serialportnum]=1;//磁盘模式

            if(IsUdisk[serialportnum]!="")
            {
                IsBackdll[serialportnum]=2;//磁盘模式
                qDebug() << "handleThreadResultb";
                config.WriteInfo(QString("IsUdisk[serialportnum]!=%1").arg(IsUdisk[serialportnum]));
                config.WriteInfo(QString("THREADC7,serialnumber%1").arg(serialportnum));
                emit GlobalSignals::instance().SendUiMessageNotifica(ACQUISITION_STATION,UPDATE_CONTROL_S,serialportnum+100,"",QString("%1;%2").arg(IsUdisk[serialportnum]).arg(IdentNumber[serialportnum]),DISKMODE,-1);
                //emit GlobalSignals::instance().SetLabel(serialportnum+100,"",QString("盘符路径:%1\n序列号:%2").arg(IsUdisk[SerialportNum]).arg(IdentNumber[SerialportNum]),"磁盘模式",-1);
            }
            else
            {
                qDebug() << "handleThreadResultc";
                //int index=GetMyVec("", Indet);
                if (index != 0) {

                    IdentNumber[serialportnum]=Identnumber;
                }
                IsBackdll[serialportnum]=1;
                //根据对应串口位置修改内存中设备信息3
                config.WriteInfo(QString("IsUdisk[Indet]==%1").arg(IsUdisk[serialportnum]));
                config.WriteInfo(QString("THREADC7,serialnumber%1").arg(serialportnum));
                emit GlobalSignals::instance().SendUiMessageNotifica(ACQUISITION_STATION,UPDATE_CONTROL_S,serialportnum+100,"","",TURNTABLESUCCESSFUL,-1);
                // emit GlobalSignals::instance().SetLabel(SerialportNum+100,"","","转盘成功",-1);//主进程进行这个

                qDebug() << "handleThreadResultd";
            }
        }
        IsC7=true;
        break;
    }
        //    case THREADTC7://s3,c8,c9,c6,s1
        //    {
        //        if(TCLC7RotaryTable(serialnumber,Identnumber,"000000"))
        //        {
        //            qInfo()<<"Identnumber"<<Identnumber;
        //            Identnumber = Identnumber.mid(11, 7); // 从索引10开始截取长度为8的子串
        //            qInfo()<<"Identnumber"<<Identnumber;
        //            IsBackdll[serialportnum]=1;//磁盘模式

        //            if(IsUdisk[serialportnum]!="")
        //            {
        //                IsBackdll[serialportnum]=2;//磁盘模式
        //                qDebug() << "handleThreadResultb";
        //                config.WriteInfo(QString("IsUdisk[Indet]!=%1").arg(IsUdisk[serialportnum]));
        //                config.WriteInfo(QString("THREADTC7,serialnumber%1").arg(serialportnum));
        //                emit GlobalSignals::instance().SendUiMessageNotifica(ACQUISITION_STATION,UPDATE_CONTROL_S,serialportnum+100,"",QString("%1;%2").arg(IsUdisk[serialportnum]).arg(IdentNumber[serialportnum]),DISKMODE,-1);
        //                //emit GlobalSignals::instance().SetLabel(Indet+100,"",QString("盘符路径:%1\n序列号:%2").arg(IsUdisk[SerialportNum]).arg(IdentNumber[SerialportNum]),"磁盘模式",-1);
        //            }
        //            else
        //            {
        //                qDebug() << "handleThreadResultc";
        //                //int index=GetMyVec("", Indet);
        //                if (index != 0) {

        //                    IdentNumber[serialportnum]=Identnumber;
        //                }
        //                IsBackdll[serialportnum]=1;
        //                //根据对应串口位置修改内存中设备信息3
        //                config.WriteInfo(QString("IsUdisk[Indet]==%1").arg(IsUdisk[serialportnum]));
        //                config.WriteInfo(QString("THREADTC7,serialnumber%1").arg(serialportnum));
        //                emit GlobalSignals::instance().SendUiMessageNotifica(ACQUISITION_STATION,UPDATE_CONTROL_S,serialportnum+100,"","",TURNTABLESUCCESSFUL,-1);
        //                // emit GlobalSignals::instance().SetLabel(SerialportNum+100,"","","转盘成功",-1);//主进程进行这个

        //                qDebug() << "handleThreadResultd";
        //            }
        //        }
        //        break;

        //    }
        //            case TLOGON://登录
        //            {
        //                QString ResultMess = "";
        //                int UserPrevilege = 0;
        //                http.chkUser("admin", "admin", 0, UserPrevilege, ResultMess);
        //                break;
        //            }

    case TUPLOAD://上传
    {
        UploadNum++;
        IsUpload=false;
        IsinUpload[serialportnum-100]=false;
        QString ResultMess = "";

        qDebug() << "Login successful!"<<UserID;
        config.WriteInfo(QString("TUPLOAD,Identnumber=%1").arg(Identnumber));

        IsUpload=false;
        IsinUpload[serialportnum-100]=false;
        //        if(http.V6GetUserByPoliceNum(UserID, Password)==1)
        //        {
        qDebug() << "Login successful!"<<UserID;
        config.WriteInfo(QString("TUPLOAD,Identnumber=%1").arg(Identnumber));
        config.WriteInfo(QString("TUPLOAD,Device=%1").arg(Device));
        if(Device!="")
        {
            QString sourceDirPath = QString("%1").arg(Device);
            QString destinationDirPath = config.UploadUrl;
            // 获取当前日期和时间
            QDateTime dateTime = QDateTime::currentDateTime();
            // 获取日期和时间
            QDate date = dateTime.date(); // 获取日期
            QTime time = dateTime.time(); // 获取时间
            QString timestr=QString("%1%2").arg(date.toString("yyyyMMdd")).arg(time.toString("hhmmss"));
            Uploadtime[serialportnum-100]=timestr;
            config.WriteInfo(QString("TUPLOAD,Identnumber=%1,timestr=%2").arg(Identnumber).arg(timestr));

            //QString diskPath = "C:/";  // 你要检查的磁盘路径
            QStringList allowedExtensions = {"*.MP4", "*.JPG","*.wav","*.txt"};

            totalSize[serialportnum-100]=0;
            TemporarytotalSize[serialportnum-100]=0;
            config.GetTotalSizeOfFiles(sourceDirPath,totalSize[serialportnum-100]);

            if (totalSize[serialportnum-100] > 0) {
                config.WriteInfo(QString("otalSize[serialportnum-100]=%1").arg(totalSize[serialportnum-100]));
                if(config.WriteSaveInfo(Identnumber,"",timestr,"",UserID,destinationDirPath))
                {
                    config.WriteInfo(QString("Total size of .mp4 and .png files in%1=,is:%2MB").arg(Device).arg(totalSize[serialportnum-100]));
                    qDebug() << "Total size of .mp4 and .png files in" << Device << "is:" << totalSize[serialportnum-100] << "MB";
                    //开启线程去拷贝
                   // SourceFilePath.clear();
                    while (true)
                                  {
                                      if(config.IsPriority>0&&AppointFirstNum!=serialportnum-100)
                                      {
                                         // RecorderMent[serialportnum-100]=RECORDER_STOPUPLOAD;
                                          QThread::msleep(1000);
                                      }
                                      else
                                          break;
                                  }
                    int num=0;
                    if(AppointFirstNum==serialportnum-100)//优先口
                                {
                                    config.IsPriority=AppointFirstNum;
                                }
//                    if(AppointFirstNum==serialportnum-100)//优先口
//                    {
//                        config.copyFiles(sourceDirPath, destinationDirPath,Identnumber,timestr,UserID,sourceDirPath,IsDeleteFiles,num,-1,serialportnum-100);
//                    }
//                    else
                        config.copyFiles(sourceDirPath, destinationDirPath,Identnumber,timestr,UserID,sourceDirPath,IsDeleteFiles,num,config.UploadRate,serialportnum-100);
                    config.IsUpload[serialportnum-100]=true;
                    QString fileName=QString("%1_%2").arg(Identnumber).arg(timestr);
                    //            if(TemporarytotalSize[serialportnum-100]>=totalSize[serialportnum-100])//全部拷贝完成
                    //            {
                    //                if(http.V6uploadLogCustom(fileName,Identnumber,UserID,"")==1)
                    //                {
                    if(http.V6uploadLogCustom(fileName,Identnumber,UserID,"")!=1)
                    {
                        RetranSmission arq;
                        arq.fileName=fileName;
                        arq.Identnumber=Identnumber;
                        arq.UserID=UserID;
                        ARQList.push_back(arq);

                    }
                    //                    if(IsDeleteFiles&&num>0&&!SourceFilePath.empty())
                    //                    {
                    //                        for (auto it = SourceFilePath.begin(); it != SourceFilePath.end(); ++it)
                    //                        {
                    //                            config.WriteInfo(QString("删除成功=%1").arg(*it));
                    //                            //emit GlobalSignals::instance().Print(QString("删除成功%1").arg(*it));
                    //                            // 删除源文件
                    //                            if (!QFile::remove(*it)) {
                    //                                qDebug() << "Failed to remove file:" << *it;
                    //                            }

                    //                        }

                    //                    }
                    config.WriteInfo(QString("TUPLOAD,serialportnum=%1").arg(serialportnum));
                    Upload.Indet=TUPLOAD;
                    Upload.SerialportNum=serialportnum;
                }
            }

            emit GlobalSignals::instance().SendUiMessageNotifica(ACQUISITION_STATION,UPDATE_CONTROL_S,serialportnum,"","",UPLOADCOMPLETED,-1);
                   if( IsExtract[serialportnum-100])
                   {
                       emit GlobalSignals::instance().SendUiMessageNotifica(ACQUISITION_STATION,UPDATE_CONTROL_S,serialportnum,"","",IDLE,-1);
                   }
                   if(serialportnum-100==config.IsPriority)
                         config.IsPriority=-1;
            emit GlobalSignals::instance().ThreadTimer(serialportnum-100,false);


            IsUpload=true;
            UploadNum--;

            IsinUpload[serialportnum-100]=true;
        }
        break;


    }
    case AUTOMATIC_TUPLOAD://上传
    {
        //        IsUpload=false;
        //        IsinUpload[serialportnum-100]=false;
        config.WriteInfo(QString("AUTOMATIC_TUPLOAD"));
        QString ResultMess = "";
        // emit GlobalSignals::instance().SendUiMessageNotifica(ACQUISITION_STATION,UPDATE_CONTROL_S,serialportnum,"",QString("%1;%2").arg(UserID).arg(Identnumber),UPLOADING,-1);
        if(http.GetZFYInfo(serialportnum-100, Identnumber)==2)//已经绑定
        {
            if(IsWarnInstance)
            {
                config.WriteInfo(QString("已绑定警员编号，点击进入警情模式"));
                emit GlobalSignals::instance().SendUiMessageNotifica(ACQUISITION_STATION,UPDATE_CONTROL_S,serialportnum,"",QString("%1;%2;%3;%4").arg(userNo[serialportnum-100]).arg(userName[serialportnum-100]).arg(Identnumber).arg(unitName[serialportnum-100]),WARNBOUND,-1);
                // IsUpload=true;
            }
            else
            {
                if(userNo[serialportnum-100]!="")//设备启用了不一定有用户
                {
                    config.WriteInfo(QString("循环GetZFYInfo"));
                    if(AppointFirstNum==serialportnum-100)//优先口
                    {
                        emit GlobalSignals::instance().ThreadPriorUpload(serialportnum,userNo[serialportnum-100],"Password");
                    }
                    else
                    {
                        emit GlobalSignals::instance().ThreadUpload(serialportnum,userNo[serialportnum-100],"Password");
                    }
                }
                else
                {
                    config.WriteInfo(QString("未绑定警员编号"));
                    emit GlobalSignals::instance().SendUiMessageNotifica(ACQUISITION_STATION,UPDATE_CONTROL_S,serialportnum,"","",UNBOUND,-1);
                    // IsUpload=true;
                    //IsinUpload[serialportnum-100]=true;
                    break;
                }


            }
            //IsinUpload[serialportnum-100]=true;
            break;
        }
        else
        {
            config.WriteInfo(QString("未绑定警员编号"));
            emit GlobalSignals::instance().SendUiMessageNotifica(ACQUISITION_STATION,UPDATE_CONTROL_S,serialportnum,"","",UNBOUND,-1);
            // IsUpload=true;
            //IsinUpload[serialportnum-100]=true;
            break;
        }
        break;
    }
    case WARNING_TUPLOAD://上传
    {
        IsUpload=false;
        IsinUpload[serialportnum]=false;
        QString ResultMess = "";
        qDebug() << "WARNING_TUPLOAD Login successful!"<<UserID;
        config.WriteInfo(QString("WARNING_TUPLOAD,Identnumber=%1,SerialPort=%2").arg(Identnumber).arg(SerialPort));
        QString sourceDirPath = QString("%1/").arg(Device);
        QString destinationDirPath = config.UploadUrl;
        // 获取当前日期和时间
        QDateTime dateTime = QDateTime::currentDateTime();
        // 获取日期和时间
        QDate date = dateTime.date(); // 获取日期
        QTime time = dateTime.time(); // 获取时间
        QString timestr=QString("%1%2").arg(date.toString("yyyyMMdd")).arg(time.toString("hhmmss"));

        Uploadtime[serialportnum-100]=timestr;
        //emit GlobalSignals::instance().SendUiMessageNotifica(ACQUISITION_STATION,UPDATE_CONTROL_S,serialportnum+100,"",QString("%1;%2;%3;%4").arg(UserID).arg(userName[serialportnum]).arg(Identnumber).arg(unitName[serialportnum]),UPLOADING,-1);
        emit GlobalSignals::instance().ThreadTimer(serialportnum-100,true);
        config.WriteInfo(QString("TUPLOAD,Identnumber=%1,timestr=%2").arg(Identnumber).arg(timestr));
        if(config.WriteSaveInfo(Identnumber,"",timestr,"",UserID,destinationDirPath))
        {
            totalSize[SerialPort]=fileallsize[SerialPort];
            config.WriteInfo(QString("T totalSize[SerialPort]=%1,TemporarytotalSize[SerialPort]=%2").arg(totalSize[SerialPort]).arg(TemporarytotalSize[SerialPort]));
            //开启线程去拷贝
            //int num=config.copyFiles(sourceDirPath, destinationDirPath,Identnumber,timestr,UserID,sourceDirPath,DeleteFiles,TemporarytotalSize[serialportnum-100]);
            QString fileName=QString("%1_%2").arg(Identnumber).arg(timestr);
            config.WriteInfo(fileName);

            for(auto it=BindList.begin();it!=BindList.end();){

                if(it->SerialPort==SerialPort)
                {

                    //开启线程去拷贝
                    int num=0;
                    if(AppointFirstNum==serialportnum-100)//优先口
                    {

                        config.copyFiles(it->sourceFilePath, destinationDirPath,Identnumber,timestr,UserID,sourceDirPath,false,it->case_number,it->trafficCaseTable,it->file_type_id,num,-1);

                    }
                    else
                        config.copyFiles(it->sourceFilePath, destinationDirPath,Identnumber,timestr,UserID,sourceDirPath,false,it->case_number,it->trafficCaseTable,it->file_type_id,num,config.UploadRate);
                    if(IsDeleteFiles&&num>=1)
                    {

                        config.WriteInfo(QString("删除成功=%1").arg(it->sourceFilePath));
                        //emit GlobalSignals::instance().Print(QString("删除成功%1").arg(*it));
                        // 删除源文件
                        if (!QFile::remove(it->sourceFilePath)) {
                            qDebug() << "Failed to remove file:" << it->sourceFilePath;
                        }
                        //删除
                    }
                    it=BindList.erase(it);
                    //上传
                }
                else
                {
                    ++it;
                }
                //BindList.erase(it);

            }



            //            if(TemporarytotalSize[serialportnum]>=totalSize[serialportnum])//全部拷贝完成
            //            {

            if(http.V6uploadLogCustom(fileName,Identnumber,UserID,"")!=1)
            {
                RetranSmission arq;
                arq.fileName=fileName;
                arq.Identnumber=Identnumber;
                arq.UserID=UserID;
                ARQList.push_back(arq);
                //                      config.WriteUploadInfo("D:/Statin/R",QString("%1，%2，%3").arg(fileName).arg(Identnumber).arg(UserID));
            }
            //                    if(IsDeleteFiles&&!SourceFilePath.empty())
            //                    {
            //                        for (auto it = SourceFilePath.begin(); it != SourceFilePath.end(); ++it) {

            //                            config.WriteInfo(QString("删除成功=%1").arg(*it));
            //                            //emit GlobalSignals::instance().Print(QString("删除成功%1").arg(*it));
            //                            // 删除源文件
            //                            if (!QFile::remove(*it)) {
            //                                qDebug() << "Failed to remove file:" << *it;
            //                            }

            //                        }

            //                    }
            config.WriteInfo(QString("WARNING_TUPLOAD1,serialportnum=%1").arg(serialportnum));
            Upload.Indet=WARNING_TUPLOAD;
            Upload.SerialportNum=serialportnum;
            emit GlobalSignals::instance().SendUiMessageNotifica(ACQUISITION_STATION,UPDATE_CONTROL_S,serialportnum,"","",UPLOADCOMPLETED,-1);
            if( IsExtract[serialportnum-100])
            {
                emit GlobalSignals::instance().SendUiMessageNotifica(ACQUISITION_STATION,UPDATE_CONTROL_S,serialportnum,"","",IDLE,-1);
            }
            emit GlobalSignals::instance().ThreadTimer(serialportnum-100,false);

            //                }
            //                else
            //                {
            //                    config.WriteInfo(QString("-WARNING_TUPLOAD2,serialportnum=%1").arg(serialportnum));
            //                    Upload.Indet=-TUPLOAD;
            //                    Upload.SerialportNum=serialportnum;
            //                    emit GlobalSignals::instance().SendUiMessageNotifica(ACQUISITION_STATION,UPDATE_CONTROL_S,serialportnum+100,"","",UPLOADFAILED,-1);
            //                    emit GlobalSignals::instance().ThreadTimer(serialportnum,false);
            //                }
            //            }
            //            else
            //            {
            //                config.WriteInfo(QString("-WARNING_TUPLOAD3,serialportnum=%1").arg(serialportnum));
            //                Upload.Indet=-TUPLOAD;
            //                Upload.SerialportNum=serialportnum;
            //                emit GlobalSignals::instance().SendUiMessageNotifica(ACQUISITION_STATION,UPDATE_CONTROL_S,serialportnum+100,"","",UPLOADFAILED,-1);
            //                emit GlobalSignals::instance().ThreadTimer(serialportnum,false);
            //            }
        }
        else
        {
            config.WriteInfo(QString("-WARNING_TUPLOAD4,serialportnum=%1").arg(serialportnum));
            Upload.Indet=-TUPLOAD;
            Upload.SerialportNum=serialportnum;
            emit GlobalSignals::instance().SendUiMessageNotifica(ACQUISITION_STATION,UPDATE_CONTROL_S,serialportnum,"","",UPLOADFAILED,-1);
            emit GlobalSignals::instance().ThreadTimer(serialportnum-100,false);

        }
        IsUpload=true;
        IsinUpload[serialportnum-100]=true;
        UploadNum--;

        break;


    }
    case EPARTMENT_FILE_QUERY:
    {
        http.GetClassifcationType();
        emit GlobalSignals::instance().SendPoliceMode(ACQUISITION_STATION,DEPARTMENT_FILE_QUERY_S);
        break;
    }
    case POLICE_SITUATION_INQUIRY:
    {
        //第一个是留空，数组是0号位开始
        http.GetWarnInstanceInfo(UserID,ID,StartTime,EndTime);
        emit GlobalSignals::instance().SendPoliceMode(ACQUISITION_STATION,POLICE_SITUATION_INQUIRY_S);
        break;
    }
        //    case TUPLOADTWO://上传
        //    {
        //        QString sourceDirPath = QString("%1:/").arg(Device);
        //        QString destinationDirPath = "D:/www/sdv/Red5";
        //        // 获取当前日期和时间
        //        QDateTime dateTime = QDateTime::currentDateTime();
        //        // 获取日期和时间
        //        QDate date = dateTime.date(); // 获取日期
        //        QTime time = dateTime.time(); // 获取时间
        //        QString timestr=QString("%1%2").arg(date.toString("yyyyMMdd")).arg(time.toString("hhmmss"));
        //        if(config.WriteSaveInfo(Serialnumber,"",timestr,"",UserID))
        //        {
        //            //开启线程去拷贝
        //            int num=config.copyFiles(sourceDirPath, destinationDirPath,Serialnumber,timestr,UserID,sourceDirPath,DeleteFiles);
        //            QString fileName=QString("%1_%2").arg(Serialnumber).arg(timestr);
        //            if(http.uploadLogCustom(fileName,Serialnumber,UserID)==1)
        //            {
        //                if(DeleteFiles&&num>0&&!SourceFilePath.empty())
        //                {
        //                    for (auto it = SourceFilePath.begin(); it != SourceFilePath.end(); ++it) {

        //                        emit GlobalSignals::instance().Print(QString("删除成功%1").arg(*it));
        //                        // 删除源文件
        //                        if (!QFile::remove(*it)) {
        //                            qDebug() << "Failed to remove file:" << *it;
        //                        }

        //                    }

        //                }
        //                UploadTwo.indentID=TUPLOADTWO;
        //                UploadTwo.SerialportNum=SerialportNum;
        //                emit GlobalSignals::instance().SetLabel(SerialportNum+100,"",QString("盘符路径:%1\n序列号:%2").arg(IsUdisk[SerialportNum]).arg(IdentNumber[SerialportNum]),"上传完成",-1);
        //                //emit GlobalSignals::instance().UploadFile(THREAD_UPLOAD_TWO,SerialportNum);
        //            }
        //            else
        //            {
        //                UploadTwo.indentID=-TUPLOADTWO;
        //                UploadTwo.SerialportNum=SerialportNum;
        //                emit GlobalSignals::instance().SetLabel(SerialportNum+100,"",QString("盘符路径:%1\n序列号:%2").arg(IsUdisk[SerialportNum]).arg(IdentNumber[SerialportNum]),"上传失败",-1);
        //            }
        //            // emit GlobalSignals::instance().UploadFile(-THREAD_UPLOAD_TWO,SerialportNum);
        //        }
        //        break;
        //    }

        //    case SYSTEMINFO:
        //    {
        //        //        CPU=QString("%1%").arg(GetCPUOccupancy());
        //        //        MEMORY=QString("%1").arg(GetMemoryOccupancy());
        //        //        DISK=QString("%1").arg(GetdiskOccupancy());
        //        //        NETWORK=QString("%1/%2").arg(GetSystemNetDownloadRate(NetworkName)).arg(GetSystemNetUploadRate(NetworkName));
        //        //        emit GlobalSignals::instance().SetLabel(-1,QString("%1%").arg(GetCPUOccupancy()),"","",-1);
        //        //        emit GlobalSignals::instance().SetLabel(-2,QString("%1").arg(GetMemoryOccupancy()),"","",-1);
        //        //        emit GlobalSignals::instance().SetLabel(-3,QString("%1").arg(GetdiskOccupancy()),"","",-1);
        //        //        emit GlobalSignals::instance().SetLabel(-4,QString("%1/%2").arg(GetSystemNetDownloadRate(NetworkName)).arg(GetSystemNetUploadRate(NetworkName)),"","",-1);

        //        break;
        //    }
    }
}


bool TMC7RotaryTable(QString serialnumber,QString &Identnumber)
{

    QString text;
    int initC7=dll.TMC7TMUsbInit();
    //QThread::msleep(1000);
    int count = 0;
    pDeviceArray devList;
    int result = dll.TMC7TMdevices(&count, &devList);
    text=QString("result=%1,count=%2,devList=%3").arg(result).arg(count).arg(*devList);
    config.WriteInfo(text);
    if (initC7 == 1&&count>=1)
    {
        for(int i=0;i<=count;i++)
        {
            text=QString("serialnumber=%1,devList[i]=%2").arg(serialnumber).arg(devList[i]);
            config.WriteInfo(text);
            QString devListElementAsChar = devList[i];
            int index = devListElementAsChar.indexOf(serialnumber, 0, Qt::CaseInsensitive);

            if (index != -1) {
                //            if(serialnumber.contains(devList[i], Qt::CaseInsensitive) == 0)
                //            {
                QString matchedPart = devListElementAsChar.mid(index, serialnumber.length());
                std::string e_Snstring = matchedPart.toStdString();

                char lowerstr[50]; // Assuming a fixed size here, adjust as needed
                strcpy(lowerstr, e_Snstring.c_str());
                text=QString("serialnumber=%1,lowerstr=%2").arg(serialnumber).arg(lowerstr);
                config.WriteInfo(text);
                int deviceIndex = 0;
                QThread::msleep(2000);
                int thisres = 0;
                thisres = dll.TMC7TMconnect(lowerstr, &deviceIndex);
                //qDebug()<<"thisres="<<thisres <<"lowerstr="<< lowerstr<<"deviceIndex="<<deviceIndex;
                int g = 0;

                while (thisres != 1 && g < 3)
                {
                    thisres = dll.TMC7TMconnect(lowerstr, &deviceIndex);
                    g++;
                    //qDebug()<<"thisres="<<thisres <<"lowerstr="<< lowerstr<<"deviceIndex="<<deviceIndex;
                }


                if (thisres == 1)
                {
                    Identnumber=lowerstr;
                    bool UMS = dll.TMC7TMEntryUMSByIndex(0);
                    qDebug()<<"UMS="<<UMS <<"i="<< i;
                    if (UMS)
                    {

                        qDebug()<<"执法仪转盘成功";
                        dll.TMC7TMdisconnectByIndex(0);
                        return true;

                    }
                }
            }
        }
    }
    return false;
}
bool ZJXS2RotaryTable(QString serialnumber,QString &Identnumber,int *const Electricity)
{

    //    if(dll.ZJX_S2==nullptr||!serialnumber.contains("TCLS2")||IsC6)
    //    {
    //        qDebug()<<dll.ZJX_S2;
    //        return false;
    //    }
    //    IsS2=true;
    //    AdbClean();

    QThread::msleep(500); // Sleep for 1 second
    QString value;
    QString text;
    QByteArray byteserialnumber = serialnumber.toUtf8();
    char* deviceNameCharArray = byteserialnumber.data();
    qDebug()<<QString("deviceNameCharArray=%1").arg(deviceNameCharArray);
    int index=0;
    bool bools =  dll.ZJXS2ZFY_Connect(index,deviceNameCharArray);
    qDebug()<<QString("bools=%1").arg(bools);
    text=QString("bools=%1,deviceNameCharArray=%2").arg(bools).arg(deviceNameCharArray);
    //emit GlobalSignals::instance().WriteLog(text);
    if (!bools)
    {
        qDebug()<<"TCL_S2找不到设备";
    }

    else {
        if(config.ReadInfo("./ZJX_S2/pwd.ini",value))//已经获取的路径文件
        {

            QStringList list = value.split(";");

            if (list.length() > 1) {
                foreach (QString item, list) {
                    if(item!=""&&item.length()==6)
                    {
                        qDebug()<<"item="<<item;
                        QByteArray byteArray = item.toUtf8();
                        char *password = new char[7];
                        strcpy(password, byteArray.constData());

                        unsigned short iRet = -1;
                        bools = dll.ZJXS2Init_Device(password,&iRet);
                        qDebug()<<QString("bools=%1,password=%2").arg(bools).arg(password);
                        //  emit GlobalSignals::instance().WriteLog(text);
                        int i=0;
                        while (i<3) {
                            QThread::msleep(500);
                            if (bools == 1)
                            {
                                break;
                            }
                            bools = dll.ZJXS2Init_Device(password,&iRet);
                            qDebug()<<QString("bools=%1,password=%2").arg(bools).arg(password);
                            //emit GlobalSignals::instance().WriteLog(text);

                            i++;
                        }
                        if (bools)
                        {

                            bools = dll.ZJXS2SyncDevTime(password,&iRet);

                            QThread::msleep(500); // Sleep for 1 second

                            text=QString("S2 时间校准bools=%1").arg(bools);
                            qDebug()<<text;

                            bools = dll.ZJXS2ReadDeviceResolution(Electricity,password,&iRet);
                            QThread::msleep(500); // Sleep for 1 second
                            text=QString("S2 电量Battery=%1").arg(*Electricity);

                            qDebug()<<text;

                            bools = dll.ZJXS2SetMSDC(password,&iRet);
                            text=QString("bools=%1,password=%2").arg(bools).arg(password);
                            //emit GlobalSignals::instance().WriteLog(text);
                            if(bools)
                            {
                                qDebug()<<"TMS2转盘成功.序列号为="<<Identnumber;
                                //IsS2=false;
                                return true;
                            }
                        }

                    }
                }
            }else {
                qDebug() << "字符串中没有分号：" << value;
            }
        }
    }
    // IsS2=false;
    return false;
}
bool TCLC6RotaryTable(QString serialnumber,QString &Identnumber)
{

    QString text;

    int initC6=dll.TCLC6TMUsbInit();
    qDebug()<<initC6;
    QThread::msleep(1000);
    initC6=dll.TCLC6TMUsbInit();
    qDebug()<<initC6;
    text=QString("initC6=%1").arg(initC6);
    config.WriteInfo(text);
    //
    //    int count = 0;
    //    pDeviceArray devList;

    //    int result = dll.TCLC6TMdevices(&count, &devList);
    //    text=QString("result=%1,count=%2,devList=%3").arg(result).arg(count).arg(*devList);
    //    config.WriteInfo(text);
    //    //    qDebug()<<"result="<<result <<"count="<< count<<"devList="<<*devList;
    //    if (initC6 == 1&&count>=1)
    //    {
    //        for(int i=0;i<count;i++)
    //        {
    //            text=QString("serialnumber=%1,devList[i]=%2").arg(serialnumber).arg(devList[i]);
    //            config.WriteInfo(text);
    //            if(serialnumber.compare(devList[i], Qt::CaseInsensitive) == 0)
    //            {

    //                int thisres = 0;
    //                int deviceIndex = 0;
    //                thisres = dll.TCLC6TMconnect(devList[i], &deviceIndex);

    //                text=QString("thisres=%1,lowerstr=%2,deviceIndex=%3").arg(thisres).arg(devList[i]).arg(deviceIndex);
    //                config.WriteInfo(text);
    //                if (thisres == 1)
    //                {
    //                    bool UMS = dll.TCLC6TMEntryUMSByIndex(0);
    //                    text=QString("UMS=%1,i=%2").arg(UMS).arg(i);
    //                    config.WriteInfo(text);
    //                    qDebug()<<"UMS="<<UMS <<"i="<< i;
    //                    if (UMS)
    //                    {
    //                        Identnumber=devList[i];
    //                        qDebug()<<"执法仪转盘成功";
    //                        dll.TCLC6TMdisconnectByIndex(0);
    //                        config.WriteInfo(text);
    //                        return true;
    //                    }
    //                }
    //            }
    //        }

    //        // }
    //    }
    return false;
}
//bool TCLT6RotaryTable(QString serialnumber,QString &Identnumber,char *pwd)
//{
//    //R2要等待开机动画结束转成磁盘才可以，不然会再次重启
//    //QThread::msleep(1000);
//    //R2要等待开机动画结束转成磁盘才可以，不然会再次重启
//    QString text;
//    QString processName = "TMUsb.exe";
//    QProcess process;
//    process.start("taskkill", QStringList() << "/F" << "/IM" << processName);
//    process.waitForFinished(-1); // 等待进程完成
//    processName = "adb.exe";
//    process.start("taskkill", QStringList() << "/F" << "/IM" << processName);
//    process.waitForFinished(-1); // 等待进程完成
//    QThread::msleep(1000);
//    // char* InitCode=new char;
//    int iRet=0;
//    std::string e_Snstring="TCLT6";
//    char lowerstr[8]; // Assuming a fixed size here, adjust as needed
//    strcpy(lowerstr, e_Snstring.c_str());
//    bool initT6=dll.TCLT6InitDevice(lowerstr,&iRet);
//    text=QString("initT6=%1,InitCode=%2,iRet=%3").arg(initT6).arg(lowerstr).arg(iRet);
//    config.WriteInfo(text);
//    qDebug()<<"text="<<text;
//    qDebug()<<initT6;
//    if(initT6)
//    {
//        bool GetDIDT6=dll.TCLT6GetDeviceID(lowerstr,&iRet);
//        Identnumber= QString::fromUtf8(lowerstr);
//        text=QString("GetDIDT6=%1,InitCode=%2,iRet=%3").arg(initT6).arg(lowerstr).arg(iRet);
//        qDebug()<<"text="<<text;
//        config.WriteInfo(text);
//        if(GetDIDT6)
//        {
//            char* police_num=pwd;
//            bool a=dll.TCLT6SetMSDC(police_num,&iRet);
//            text=QString("police_num=%1").arg(QString::fromStdString(police_num));
//            qDebug()<<text;
//            qDebug()<<"a"<<a;
//            return a;

//        }
//    }
//    return false;
//}
//bool TCLS8RotaryTable(QString serialnumber,QString &Identnumber)
//{

//    //    QString processName = "TMUsb.exe";
//    //    QProcess process;
//    //    process.start("taskkill", QStringList() << "/F" << "/IM" << processName);
//    //    process.waitForFinished(-1); // 等待进程完成
//    std::string e_Snstring = serialnumber.toStdString();
//    char lowerstr[50]; // Assuming a fixed size here, adjust as needed
//    strcpy(lowerstr, e_Snstring.c_str());

//    int deviceIndex = 0;
//    qDebug()<<"TCLS8RotaryTable";

//    bool IsTCLS8=dll.TCLS8GetDeviceID(lowerstr,&deviceIndex);
//    if (IsTCLS8)
//    {
//        int batteryLe=0;
//        int iRet=0;
//        dll.TCLS8ReadDeviceBattery(&batteryLe,&iRet);
//    }
//}
//bool TCL3ARotaryTable(QString serialnumber,QString &Identnumber,char *pwd)
//{
//    QString text;
//    QString processName = "TMUsb.exe";
//    QProcess process;
//    process.start("taskkill", QStringList() << "/F" << "/IM" << processName);
//    process.waitForFinished(-1); // 等待进程完成
//    QThread::msleep(1000);
//    char* cID=new char;
//    short iRet=2;

//    bool initR1=dll.TCL3AfindNewDVSlot(iRet);
//    text=QString("TCL3A=%1,iRet=%2").arg(initR1).arg(iRet);
//    config.WriteInfo(text);
//    qDebug()<<"text="<<text;
//    if(initR1==true)
//    {
//        initR1=dll.TCL3AGetDeviceID(iRet,cID,33);

//        text=QString("TCL3A=%1,iRet=%2,iRet=%3").arg(initR1).arg(cID).arg(iRet);
//        if(initR1==true)
//        {
//            Identnumber= QString::fromUtf8(cID);
//            config.WriteInfo(text);
//            qDebug()<<"text="<<text;
//            if(initR1==true)
//            {
//                initR1=dll.TCL3AchkDVPwd(iRet,pwd);
//                text=QString("TCL3A=%1,iRet=%2,iRet=%3").arg(initR1).arg(cID).arg(iRet);
//                config.WriteInfo(text);
//                qDebug()<<"text="<<text;

//                initR1=dll.TCL3ASetMSDC(iRet);
//                text=QString("TCL3A=%1,iRet=%2,iRet=%3").arg(initR1).arg(cID).arg(iRet);
//                config.WriteInfo(text);
//                qDebug()<<"text="<<text;
//                if(initR1==true)
//                {
//                    return true;
//                }
//            }
//        }
//    }
//    return false;
//}
//bool TCLR1RotaryTable(QString serialnumber,QString &Identnumber,char *pwd)
//{
//    QString text;
//    QString processName = "TMUsb.exe";
//    QProcess process;
//    process.start("taskkill", QStringList() << "/F" << "/IM" << processName);
//    process.waitForFinished(-1); // 等待进程完成
//    QThread::msleep(1000);
//    char* cID=new char;
//    unsigned short iRet=0;

//    bool initR1=dll.TCLR1GetIDCode(cID,&iRet);
//    text=QString("initR1=%1,iRet=%2,iRet=%3").arg(initR1).arg(cID).arg(iRet);
//    config.WriteInfo(text);
//    qDebug()<<"text="<<text;

//    initR1=dll.TCLR1Init_Device(cID,&iRet);
//    text=QString("initR1=%1,iRet=%2,iRet=%3").arg(initR1).arg(cID).arg(iRet);
//    Identnumber= QString::fromUtf8(cID);
//    config.WriteInfo(text);
//    qDebug()<<"text="<<text;
//    if(iRet==1)
//    {
//        bool GetR1=dll.TCLR1GetZFYInfo(&dll.ZFYINFO,pwd,&iRet);
//        text=QString("GetR1=%1,InitCode=%2,iRet=%3").arg(GetR1).arg(pwd).arg(iRet);
//        qDebug()<<"text="<<text;
//        config.WriteInfo(text);
//        int battery = 0;
//        GetR1=dll.TCLR1ReadDeviceBatteryDumpEnergy(&battery,pwd,&iRet);
//        text=QString("GetR1=%1,InitCode=%2,iRet=%3").arg(GetR1).arg(pwd).arg(iRet);
//        qDebug()<<"text="<<text;
//        config.WriteInfo(text);
//        GetR1=dll.TCLR1SetMSDC(pwd,&iRet);
//        text=QString("GetR1=%1,InitCode=%2,iRet=%3").arg(GetR1).arg(pwd).arg(iRet);
//        qDebug()<<"text="<<text;
//        config.WriteInfo(text);
//    }
//    return false;
//}
//bool TCLC7RotaryTable(QString serialnumber,QString &Identnumber,char *pwd)
//{
//    QString text;
//    QString processName = "TUsb.exe";
//    QProcess process;
//    process.start("taskkill", QStringList() << "/F" << "/IM" << processName);
//    process.waitForFinished(-1); // 等待进程完成

//    char* cID=new char;
//    unsigned short iRet=0;
//    char* name=new char;
//    name="TCLC7";
//    bool initR1=dll.TCLC7Init_Device2(name,cID,&iRet);
//    text=QString("TCLC7=%1,iRet=%2,iRet=%3").arg(initR1).arg(cID).arg(iRet);
//    config.WriteInfo(text);
//    qDebug()<<"text="<<text;

//    initR1=dll.TCLC7GetIDCode2(name,cID,&iRet);
//    text=QString("TCLC7=%1,iRet=%2,iRet=%3").arg(initR1).arg(cID).arg(iRet);
//    config.WriteInfo(text);
//    qDebug()<<"text="<<text;
//    if(iRet==1)
//    {
//        //        bool GetR1=dll.TCLR1GetZFYInfo(&dll.ZFYINFO,pwd,&iRet);
//        //        text=QString("GetR1=%1,InitCode=%2,iRet=%3").arg(GetR1).arg(pwd).arg(iRet);
//        //        qDebug()<<"text="<<text;
//        //        config.WriteInfo(text);
//        int battery = 0;
//        bool GetR1=dll.TCLC7ReadDeviceBatteryDumpEnergy2(&battery,cID,pwd,&iRet);
//        text=QString("GetR1=%1,InitCode=%2,iRet=%3").arg(GetR1).arg(pwd).arg(iRet);
//        qDebug()<<"text="<<text;
//        config.WriteInfo(text);
//        GetR1=dll.TCLC7SetMSDC2(cID,pwd,&iRet);
//        text=QString("GetR1=%1,InitCode=%2,iRet=%3").arg(GetR1).arg(pwd).arg(iRet);
//        qDebug()<<"text="<<text;
//        config.WriteInfo(text);
//    }
//    return false;
//}
//void terminateProcessByPath(const QString& processPath)
//{
//    //将当前工作目录设置为应用程序所在的目录
//    QDir::setCurrent(QCoreApplication::applicationDirPath());
//    QProcess process;
//    process.start("tasklist", QStringList() << "/FO" << "CSV" << "/NH");
//    process.waitForFinished();

//    QByteArray output = process.readAllStandardOutput();
//    QString outputStr(output);

//    // 按行分割输出
//    QStringList lines = outputStr.split("\r\n", QString::SkipEmptyParts);

//    for (const QString& line : lines) {
//        QStringList columns = line.split(",");

//        if (columns.count() >= 2) {
//            QString imageName = columns[0].remove("\"");
//            QString filePath = columns[1].remove("\"");

//            if (filePath == processPath) {
//                QString processId = columns[1].remove("\"");
//                QProcess::execute("taskkill", QStringList() << "/F" << "/PID" << processId);
//            }
//        }
//    }
//}

